<!--
 * @Descripttion: 
 * @version: @ 1.0.0
 * @Author: ZJZ
 * @Date: 2021-04-26 16:43:04
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-06-01 15:41:36
-->
<template>
  <div>
    <el-drawer
      title="批次信息"
      :visible.sync="dialog.batchDrawer"
      :direction="direction"
      :with-header="false"
      size="60%"
      :modal="false"
    >
      <div class="head">
        <div class="header">
          <div class="img">
            <img src="@/assets/images/icon-batch.png" alt="" />
            <h3>批次信息</h3>
          </div>
          <div class="btn">
            <el-button
              type="primary"
              size="default"
              @click="edit"
              :disabled="disabled"
              v-hasPermi="['registerset:batchexa:edit']"
            >
              编辑
            </el-button>
            <el-button
              type="danger"
              plain
              size="default"
              @click="del"
              v-hasPermi="['registerset:batchexa:del']"
            >
              删除
            </el-button>
          </div>
        </div>
        <div class="footer">
          <div class="information">
            <span>批次名称</span>
            <h4>{{ drawerDate.batchName }}</h4>
          </div>
          <div class="information">
            <span>考试名称</span>
            <h4>{{ drawerDate.examinationName }}</h4>
          </div>
          <div class="information">
            <span>报名开始时间</span>
            <h4>{{ drawerDate.enrollStart }}</h4>
          </div>
          <div class="information">
            <span>报名结束时间</span>
            <h4>{{ drawerDate.enrollEnd }}</h4>
          </div>
        </div>
      </div>
      <div class="strip"></div>
      <div class="specific">
        <el-tabs v-model="activeName" type="border-card">
          <el-tab-pane label="详细资料" name="first">
            <div class="basics">基础信息</div>
            <div class="basics-information">
              <div class="subclass">
                <span>使用区域：{{ drawerDate.areaName }}</span>
              </div>
              <div class="subclass">
                <span>预计考试开始时间：{{ drawerDate.examinationStart }}</span>
              </div>
              <div class="subclass">
                <span>预计考试结束时间：{{ drawerDate.examinationEnd }}</span>
              </div>
              <div class="subclass">
                <span>终端缴费金额：{{ drawerDate.terminalPrice }}</span>
              </div>
              <div class="subclass">
                <span>同行缴费金额：{{ drawerDate.peersPrice }}</span>
              </div>
              <div class="subclass">
                <span>vip客户缴费金额：{{ drawerDate.memberPrice }}</span>
              </div>
              <div class="subclass">
                <span>
                  是否允许个人报名：{{
                    drawerDate.statusAllow == "1" ? "是" : "否"
                  }}
                </span>
              </div>
              <div class="subclass">
                <span>
                  是否允许补考：{{ drawerDate.makeUp == "1" ? "是" : "否" }}
                </span>
              </div>
            </div>
            <div class="system">系统信息</div>
            <div class="basics-information">
              <div class="subclass">
                <span>创建人：{{ drawerDate.createBy }}</span>
              </div>
              <div class="subclass">
                <span>负责人：{{ drawerDate.userName }}</span>
              </div>
              <div class="subclass">
                <span>创建时间：{{ drawerDate.createTime }}</span>
              </div>
              <div class="subclass">
                <span>更新时间：{{ drawerDate.updateTime }}</span>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane label="团队人员" name="seventh">
            <div class="team">
              <div class="team-right">
                <el-button type="primary" size="default" plain @click="addTeam">
                  添加团队成员
                </el-button>
                <el-button type="primary" size="default" plain @click="outTeam">
                  退出团队
                </el-button>
              </div>
              <div class="team-left" v-if="selShow">
                <el-button
                  type="primary"
                  size="default"
                  plain
                  :disabled="tDisabled"
                  @click="editTeam"
                >
                  编辑
                </el-button>
                <el-button
                  type="primary"
                  size="default"
                  plain
                  @click="removeTeam"
                >
                  移除
                </el-button>
              </div>
            </div>
            <el-table
              :data="teamData"
              height="3rem"
              @selection-change="teamChange"
            >
              <template slot="empty" class="emptyBg">
                <img src="@/assets/images/empty.jpg" alt="" />
              </template>
              <el-table-column type="selection" width="55"> </el-table-column>
              <el-table-column label="姓名" prop="nickName"> </el-table-column>
              <el-table-column label="部门" prop="deptName"> </el-table-column>
              <el-table-column label="团队角色">
                <template slot-scope="scope">
                  {{ scope.row.isAdmin == true ? "负责人" : "成员" }}
                </template>
              </el-table-column>
              <el-table-column label="有效时间" prop="expire">
                <template slot-scope="scope">
                  {{ scope.row.expire == null ? "不限" : scope.row.expire }}
                </template>
              </el-table-column>
              <el-table-column label="权限">
                <template slot-scope="scope">
                  {{
                    scope.row.isAdmin == true
                      ? "负责人"
                      : scope.row.readonly == 0
                      ? "读写"
                      : "只读"
                  }}
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="操作记录" name="second">
            <div
              class="operation"
              v-for="(item, index) in Operation"
              :key="index"
            >
              <div class="user">
                <div class="portrait">
                  <img :src="item.avatar" alt="" />
                </div>
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="item.createBy"
                  placement="top"
                >
                  <div class="name">{{ item.createBy }}</div>
                </el-tooltip>
              </div>
              <div class="record">
                <div class="time">{{ item.createTime }}</div>
                <div class="content">
                  <div>{{ item.content }}</div>
                </div>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-drawer>
    <edit-user
      :dialog="dialog"
      :teamForm="teamForm"
      v-if="dialog.editTeamShowEject"
    ></edit-user>
  </div>
</template>

<script>
import { delexamBatch } from "@/api/signUp";
import { OperationRecord } from "@/api/currency";
import { teamList, deleteTeam, withdrawTeam } from "@/api/team";
import EditUser from "@/components/joinTeam/editUser.vue";
export default {
  components: {
    EditUser,
  },
  props: {
    dialog: {
      type: Object,
      required: true,
    },
    drawerDate: {
      type: Object,
      required: true,
    },
    batchForm: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      disabled: false,
      teamIds: [],
      teamForm: {},
      selShow: false,
      tDisabled: true,
      teamMul: [],
      teamData: [],
      activeName: "first",
      direction: "rtl",
      Operation: [],
    };
  },
  created() {},
  watch: {
    drawerDate: {
      deep: true,
      handler() {
        if (this.drawerDate !== {}) {
          console.log(this.drawerDate);
          if (this.drawerDate.openState == "1") {
            this.disabled = true;
          } else {
            this.disabled = false;
          }
          this.getRecord();
          this.getTeamList();
        }
      },
    },
  },
  methods: {
    // 退出团队
    outTeam() {
      withdrawTeam({
        module: 1,
        entity: this.drawerDate.id,
        userId: this.drawerDate.userId,
      }).then((res) => {
        this.$message.success(res.msg);
        this.getTeamList();
      });
    },
    // 移除团队成员
    removeTeam() {
      deleteTeam({
        userId: this.drawerDate.userId,
        ids: this.teamIds,
      }).then((res) => {
        this.$message.success(res.msg);
        this.getTeamList();
      });
    },
    // 编辑团队列表
    editTeam() {
      this.dialog.editTeamShowEject = true;
      this.$nextTick(function () {
        this.dialog.editTeamShow = true;
      });
    },
    // 团队列表选中
    teamChange(val) {
      this.teamMul = val;
      this.teamIds = [];
      if (val.length !== 0) {
        this.selShow = true;
        this.teamForm = val[0];
        val.forEach((item) => {
          this.teamIds.push(item.id);
        });
      } else {
        this.selShow = false;
      }
      if (val.length > 1) {
        this.tDisabled = true;
      } else {
        this.tDisabled = false;
      }
    },
    // 添加团队成员
    addTeam() {
      this.$parent.entities.push(this.drawerData.id);
      this.$parent.addTeam();
    },
    // 获取团队成员
    getTeamList() {
      teamList({
        module: 1,
        entity: this.drawerDate.id,
        userId: this.drawerDate.userId,
      }).then((res) => {
        this.teamData = res.data;
      });
    },
    // 获取操作记录
    getRecord() {
      console.log(this.drawerDate.id);
      OperationRecord({
        columnId: 10,
        entryId: this.drawerDate.id,
      }).then((res) => {
        this.Operation = res.data;
      });
    },
    edit() {
      this.$parent.id = this.drawerDate.id;
      this.$parent.edit();
    },
    async del() {
      let arr = [this.drawerDate.id];
      const confirmResult = await this.$confirm(
        "此操作将永久删除该职位, 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).catch((err) => err);
      /*如果用户确认打印confirm,如果用户取消显示cancel*/
      if (confirmResult !== "confirm") {
        return this.$message.info("已取消删除!");
      } else {
        let res = await delexamBatch(arr);
        this.$parent.getDataList();
        this.$message.success("删除成功！");
      }
    },
  },
};
</script>

<style lang="less" scoped>
.head {
  padding: 29px;
  width: 100%;
  height: 155px;
  border-bottom: 1px solid #ececec;
  span {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
  }
  .header {
    display: flex;
    justify-content: space-between;
    .img {
      transform: translateY(-15px);
      img {
        vertical-align: middle;
        margin-right: 12px;
      }
      h3 {
        display: inline-block;
      }
    }
  }
  .footer {
    display: flex;
    .information {
      display: flex;
      flex-direction: column;
      margin-right: 80px;
      h4 {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #2b2b2b;
        margin-top: 12px;
      }
    }
  }
}
.strip {
  width: 100%;
  height: 16px;
  background: #fafafa;
  border: 1px solid #ececec;
  /deep/.el-tabs__nav-scroll {
    background-color: #f5f8fa;
  }
}

/deep/ .el-tab-pane {
  padding-left: 24px;
  height: 73vh;
  overflow: auto;
}
.basics {
  position: relative;
  font-size: 14px;
}
.basics::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 3px;
  width: 3px;
  height: 14px;
  background: #1267fa;
}

.system {
  margin-top: 70px;
  position: relative;
  font-size: 14px;
}
.system::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 3px;
  width: 3px;
  height: 14px;
  background: #1267fa;
}
.basics-information {
  display: flex;
  flex-wrap: wrap;
  .subclass {
    width: 249px;
    margin-top: 30px;
    margin-right: 150px;
    span {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 14px;
    }
  }
}
.operation {
  display: flex;
  .user {
    display: flex;
    .portrait {
      width: 30px;
      height: 30px;
      border-radius: 30px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 30px;
      }
    }
    .name {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      width: 100px;
      height: 30px;
      line-height: 30px;
      margin-left: 14px;
    }
  }
  .record {
    padding-left: 21px;
    margin-left: 44px;
    border-left: 1px dotted #dbdcdb;
    .time {
      font-size: 14px;
      position: relative;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 14px;
    }
    .time::before {
      content: "";
      position: absolute;
      left: -27px;
      width: 11px;
      height: 11px;
      background-color: #000;
      transform: rotate(45deg);
    }
    .content {
      padding-top: 10px;
      padding-bottom: 10px;
    }
  }
}
.team {
  display: flex;
  justify-content: space-between;
}
</style>